﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SweptVolume.CUiSVInterferenceZoneDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.SweptVolume;

public class CUiSVInterferenceZoneDlg : TxForm
{
  private Container components;
  private TxObjEditBoxCtrl m_operation_txObjEditBoxCtrl;
  private TxObjEditBoxCtrl m_checkWith_txObjEditBoxCtrl;
  private Label m_operation_label;
  private Label m_checkWith_label;
  private Label m_clearance_label;
  private CheckBox m_tcpTrack_checkBox;
  private CheckBox m_notes_checkBox;
  private CheckBox m_displaySimulation_checkBox;
  private Button m_report_button;
  private Button m_apply_button;
  private Button m_close_button;
  private CApSVInterferenceZone m_application;
  private TxNumericEditBoxCtrl m_clearance_numericUpDown;
  private CheckBox m_includeCables_checkBox;
  private CCoSVInterferenceZoneCmd m_cmd;
  private const string INTERFERENCE_ZONE_DLG_INCLUDE_CABLES = "SWEPT_VOLUME_MULTIPLE_OPERATIONS_DLG_INCLUDE_CABLES";

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiSVInterferenceZoneDlg));
    this.m_operation_txObjEditBoxCtrl = new TxObjEditBoxCtrl();
    this.m_checkWith_txObjEditBoxCtrl = new TxObjEditBoxCtrl();
    this.m_operation_label = new Label();
    this.m_checkWith_label = new Label();
    this.m_clearance_label = new Label();
    this.m_tcpTrack_checkBox = new CheckBox();
    this.m_notes_checkBox = new CheckBox();
    this.m_displaySimulation_checkBox = new CheckBox();
    this.m_report_button = new Button();
    this.m_apply_button = new Button();
    this.m_close_button = new Button();
    this.m_clearance_numericUpDown = new TxNumericEditBoxCtrl();
    this.m_includeCables_checkBox = new CheckBox();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_operation_txObjEditBoxCtrl, "m_operation_txObjEditBoxCtrl");
    this.m_operation_txObjEditBoxCtrl.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.m_operation_txObjEditBoxCtrl.ListenToPick = false;
    ((Control) this.m_operation_txObjEditBoxCtrl).Name = "m_operation_txObjEditBoxCtrl";
    this.m_operation_txObjEditBoxCtrl.Object = (ITxObject) null;
    this.m_operation_txObjEditBoxCtrl.PickAndClear = false;
    this.m_operation_txObjEditBoxCtrl.PickLevel = (TxPickLevel) 1;
    this.m_operation_txObjEditBoxCtrl.PickOnly = false;
    this.m_operation_txObjEditBoxCtrl.ReadOnly = false;
    this.m_operation_txObjEditBoxCtrl.ValidatorType = (TxValidatorType) 0;
    this.m_operation_txObjEditBoxCtrl.TypeInvalid += new EventHandler(this.m_operation_txObjEditBoxCtrl_TypeInvalid);
    this.m_operation_txObjEditBoxCtrl.TypeValid += new EventHandler(this.m_operation_txObjEditBoxCtrl_TypeValid);
    this.m_operation_txObjEditBoxCtrl.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_operation_txObjEditBoxCtrl_Picked);
    componentResourceManager.ApplyResources((object) this.m_checkWith_txObjEditBoxCtrl, "m_checkWith_txObjEditBoxCtrl");
    this.m_checkWith_txObjEditBoxCtrl.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.m_checkWith_txObjEditBoxCtrl.ListenToPick = true;
    ((Control) this.m_checkWith_txObjEditBoxCtrl).Name = "m_checkWith_txObjEditBoxCtrl";
    this.m_checkWith_txObjEditBoxCtrl.Object = (ITxObject) null;
    this.m_checkWith_txObjEditBoxCtrl.PickAndClear = false;
    this.m_checkWith_txObjEditBoxCtrl.PickLevel = (TxPickLevel) 1;
    this.m_checkWith_txObjEditBoxCtrl.PickOnly = false;
    this.m_checkWith_txObjEditBoxCtrl.ReadOnly = false;
    this.m_checkWith_txObjEditBoxCtrl.ValidatorType = (TxValidatorType) 1;
    this.m_checkWith_txObjEditBoxCtrl.TypeInvalid += new EventHandler(this.m_checkWith_txObjEditBoxCtrl_TypeInvalid);
    this.m_checkWith_txObjEditBoxCtrl.TypeValid += new EventHandler(this.m_checkWith_txObjEditBoxCtrl_TypeValid);
    this.m_checkWith_txObjEditBoxCtrl.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_checkWith_txObjEditBoxCtrl_Picked);
    componentResourceManager.ApplyResources((object) this.m_operation_label, "m_operation_label");
    this.m_operation_label.Name = "m_operation_label";
    componentResourceManager.ApplyResources((object) this.m_checkWith_label, "m_checkWith_label");
    this.m_checkWith_label.Name = "m_checkWith_label";
    componentResourceManager.ApplyResources((object) this.m_clearance_label, "m_clearance_label");
    this.m_clearance_label.Name = "m_clearance_label";
    this.m_tcpTrack_checkBox.Checked = true;
    this.m_tcpTrack_checkBox.CheckState = CheckState.Checked;
    componentResourceManager.ApplyResources((object) this.m_tcpTrack_checkBox, "m_tcpTrack_checkBox");
    this.m_tcpTrack_checkBox.Name = "m_tcpTrack_checkBox";
    this.m_tcpTrack_checkBox.CheckedChanged += new EventHandler(this.m_tcpTrack_checkBox_CheckedChanged);
    this.m_notes_checkBox.Checked = true;
    this.m_notes_checkBox.CheckState = CheckState.Checked;
    componentResourceManager.ApplyResources((object) this.m_notes_checkBox, "m_notes_checkBox");
    this.m_notes_checkBox.Name = "m_notes_checkBox";
    componentResourceManager.ApplyResources((object) this.m_displaySimulation_checkBox, "m_displaySimulation_checkBox");
    this.m_displaySimulation_checkBox.Name = "m_displaySimulation_checkBox";
    componentResourceManager.ApplyResources((object) this.m_report_button, "m_report_button");
    this.m_report_button.Name = "m_report_button";
    this.m_report_button.Click += new EventHandler(this.m_report_button_Click);
    componentResourceManager.ApplyResources((object) this.m_apply_button, "m_apply_button");
    this.m_apply_button.Name = "m_apply_button";
    this.m_apply_button.Click += new EventHandler(this.m_apply_button_Click);
    componentResourceManager.ApplyResources((object) this.m_close_button, "m_close_button");
    this.m_close_button.DialogResult = DialogResult.Cancel;
    this.m_close_button.Name = "m_close_button";
    this.m_close_button.Click += new EventHandler(this.m_close_button_Click);
    componentResourceManager.ApplyResources((object) this.m_clearance_numericUpDown, "m_clearance_numericUpDown");
    this.m_clearance_numericUpDown.BorderStyle = BorderStyle.Fixed3D;
    this.m_clearance_numericUpDown.LowerBound = 0.0;
    ((Control) this.m_clearance_numericUpDown).Name = "m_clearance_numericUpDown";
    this.m_clearance_numericUpDown.ReadOnly = false;
    this.m_clearance_numericUpDown.StepSize = 1.0;
    this.m_clearance_numericUpDown.TextAlign = HorizontalAlignment.Left;
    this.m_clearance_numericUpDown.ThousandsSeparator = false;
    this.m_clearance_numericUpDown.UpperBound = 1000000.0;
    this.m_clearance_numericUpDown.UseDecimalPlacesFromOption = true;
    this.m_clearance_numericUpDown.Value = 0.0;
    this.m_clearance_numericUpDown.ValueType = (TxNumericEditValueType) 3;
    componentResourceManager.ApplyResources((object) this.m_includeCables_checkBox, "m_includeCables_checkBox");
    this.m_includeCables_checkBox.Name = "m_includeCables_checkBox";
    ((Form) this).AcceptButton = (IButtonControl) this.m_apply_button;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((Form) this).CancelButton = (IButtonControl) this.m_close_button;
    ((Control) this).Controls.Add((Control) this.m_includeCables_checkBox);
    ((Control) this).Controls.Add((Control) this.m_clearance_numericUpDown);
    ((Control) this).Controls.Add((Control) this.m_report_button);
    ((Control) this).Controls.Add((Control) this.m_tcpTrack_checkBox);
    ((Control) this).Controls.Add((Control) this.m_notes_checkBox);
    ((Control) this).Controls.Add((Control) this.m_operation_label);
    ((Control) this).Controls.Add((Control) this.m_operation_txObjEditBoxCtrl);
    ((Control) this).Controls.Add((Control) this.m_checkWith_txObjEditBoxCtrl);
    ((Control) this).Controls.Add((Control) this.m_checkWith_label);
    ((Control) this).Controls.Add((Control) this.m_clearance_label);
    ((Control) this).Controls.Add((Control) this.m_displaySimulation_checkBox);
    ((Control) this).Controls.Add((Control) this.m_apply_button);
    ((Control) this).Controls.Add((Control) this.m_close_button);
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiSVInterferenceZoneDlg);
    ((Form) this).Closed += new EventHandler(this.CUiSVInterferenceZoneDlg_Closed);
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiSVInterferenceZoneDlg_FormClosing);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  public CUiSVInterferenceZoneDlg(CCoSVInterferenceZoneCmd cmd)
  {
    this.InitializeComponent();
    ((Control) this).MinimumSize = ((Form) this).Size;
    ((Control) this).MaximumSize = new Size(int.MaxValue, ((Form) this).Size.Height);
    this.m_cmd = cmd;
    this.m_application = new CApSVInterferenceZone();
    cmd.DialogIsOpen(true);
  }

  public virtual void OnInitTxForm()
  {
    // ISSUE: unable to decompile the method.
  }

  private void initIncludeCables()
  {
    this.m_includeCables_checkBox.Checked = false;
    object obj;
    TxFormSettings.RestoreFormValue((Form) this, "SWEPT_VOLUME_MULTIPLE_OPERATIONS_DLG_INCLUDE_CABLES", ref obj);
    if (obj == null)
      return;
    if (obj.ToString().ToLower() == "true")
      this.m_includeCables_checkBox.Checked = true;
    else
      this.m_includeCables_checkBox.Checked = false;
  }

  private void setUIElementsEnable(bool enable)
  {
    this.m_operation_txObjEditBoxCtrl.Enabled = enable;
    this.m_checkWith_txObjEditBoxCtrl.Enabled = enable;
    this.m_close_button.Enabled = enable;
    this.m_apply_button.Enabled = enable;
    this.m_clearance_numericUpDown.Enabled = enable;
    this.m_displaySimulation_checkBox.Enabled = enable;
    this.m_notes_checkBox.Enabled = enable;
    this.m_tcpTrack_checkBox.Enabled = enable;
    this.m_operation_label.Enabled = enable;
    this.m_checkWith_label.Enabled = enable;
    this.m_clearance_label.Enabled = enable;
    this.m_includeCables_checkBox.Enabled = enable;
    if (enable)
      return;
    this.m_report_button.Enabled = false;
  }

  private void generateReport()
  {
    if (this.m_application == null)
      return;
    this.m_application.generateReport();
  }

  private void enableApplyIfValid()
  {
    if (this.isObjectValidForControl(this.m_operation_txObjEditBoxCtrl.Object) & this.isValidCheckWithObject(this.m_checkWith_txObjEditBoxCtrl.Object))
      this.m_apply_button.Enabled = true;
    else
      this.m_apply_button.Enabled = false;
  }

  private bool isObjectValidForControl(ITxObject obj)
  {
    return CApSVHoldingObjectValidator.isObjectValidForHoldingSweptVolume(obj);
  }

  private bool isValidCheckWithObject(ITxObject obj)
  {
    return CApSVInterferenceWithValidator.IsValidForInterferenceCheck(obj);
  }

  private void reportError(EApInterferenceZoneErrorType errorCode)
  {
    ResourceManager resourceManager = new ResourceManager("DnProcessSimulateCommands.SweptVolume.StringTable", ((object) this).GetType().Assembly);
    string str1 = resourceManager.GetString("IZ_NAME");
    string str2;
    MessageBoxIcon messageBoxIcon;
    switch (errorCode)
    {
      case EApInterferenceZoneErrorType.IZ_OPERATION_FAILED:
        str2 = resourceManager.GetString("IZ_OPERATION_FAILED");
        messageBoxIcon = MessageBoxIcon.Hand;
        break;
      case EApInterferenceZoneErrorType.IZ_CHECK_WITH_OBJECT_BLANK_ERROR:
        str2 = resourceManager.GetString("IZ_CHECK_WITH_OBJECT_BLANK_ERROR");
        messageBoxIcon = MessageBoxIcon.Hand;
        break;
      case EApInterferenceZoneErrorType.IZ_FIRST_OR_LAST_LOCATION_IN_ZONE_ERROR:
        str2 = resourceManager.GetString("IZ_FIRST_OR_LAST_LOCATION_IN_ZONE_ERROR");
        messageBoxIcon = MessageBoxIcon.Exclamation;
        break;
      case EApInterferenceZoneErrorType.IZ_NO_INTERFERENCE_ZONES_FOUND:
        str2 = resourceManager.GetString("IZ_NO_INTERFERENCE_ZONES_FOUND");
        messageBoxIcon = MessageBoxIcon.Asterisk;
        break;
      default:
        str2 = "Unknown Error";
        messageBoxIcon = MessageBoxIcon.Hand;
        break;
    }
    int num = (int) TxMessageBox.Show(str2, str1, MessageBoxButtons.OK, messageBoxIcon);
  }

  private bool isSelectedOperationMountedWorkpieceOperation()
  {
    bool flag = false;
    ITxObject itxObject = this.m_operation_txObjEditBoxCtrl.Object;
    if (itxObject != null && itxObject is ITxRoboticOperation)
      flag = (itxObject as ITxRoboticOperation).IsMountedWorkpieceOperation;
    return flag;
  }

  private bool isSelectedOperationObjectFlowOperation()
  {
    bool flag = false;
    ITxObject itxObject = this.m_operation_txObjEditBoxCtrl.Object;
    if (itxObject != null)
      flag = itxObject is TxObjectFlowOperation;
    return flag;
  }

  private void validOperationSelected()
  {
    if (!this.canCreateTCPTrackForSelectedOperation() && this.m_tcpTrack_checkBox.Checked)
      this.m_tcpTrack_checkBox.Checked = false;
    this.m_checkWith_txObjEditBoxCtrl.Focus();
    this.enableApplyIfValid();
  }

  private bool canCreateTCPTrackForSelectedOperation()
  {
    bool selectedOperation = true;
    if (this.isSelectedOperationMountedWorkpieceOperation() || this.isSelectedOperationObjectFlowOperation())
      selectedOperation = false;
    return selectedOperation;
  }

  private void m_close_button_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void CUiSVInterferenceZoneDlg_Closed(object sender, EventArgs e)
  {
    this.m_application.deleteTCPFTrackerComponents();
    this.m_cmd.DialogIsOpen(false);
    TxApplication.RefreshDisplay();
  }

  private void m_operation_txObjEditBoxCtrl_Picked(
    object sender,
    TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (!this.isObjectValidForControl(args.Object))
      this.m_apply_button.Enabled = false;
    else
      this.validOperationSelected();
  }

  private void m_operation_txObjEditBoxCtrl_TypeValid(object sender, EventArgs e)
  {
    if (this.isObjectValidForControl(this.m_operation_txObjEditBoxCtrl.Object))
    {
      this.m_checkWith_txObjEditBoxCtrl.Focus();
      this.validOperationSelected();
    }
    else
      this.m_apply_button.Enabled = false;
  }

  private void m_operation_txObjEditBoxCtrl_TypeInvalid(object sender, EventArgs e)
  {
    this.m_apply_button.Enabled = false;
  }

  private void m_checkWith_txObjEditBoxCtrl_Picked(
    object sender,
    TxObjEditBoxCtrl_PickedEventArgs args)
  {
    ITxObject itxObject = args.Object;
    if (itxObject is ITxSweptVolumeHoldingObject)
    {
      ITxSweptVolumeHoldingObject volumeHoldingObject = itxObject as ITxSweptVolumeHoldingObject;
      if (((Collection<ITxObject>) volumeHoldingObject.SweptVolumes).Count > 0)
      {
        ITxObject sweptVolume = ((Collection<ITxObject>) volumeHoldingObject.SweptVolumes)[0];
        if (this.isValidCheckWithObject(sweptVolume))
          this.m_checkWith_txObjEditBoxCtrl.Object = sweptVolume;
      }
    }
    this.enableApplyIfValid();
  }

  private void m_checkWith_txObjEditBoxCtrl_TypeInvalid(object sender, EventArgs e)
  {
    this.m_apply_button.Enabled = false;
  }

  private void m_checkWith_txObjEditBoxCtrl_TypeValid(object sender, EventArgs e)
  {
    this.enableApplyIfValid();
  }

  private void m_apply_button_Click(object sender, EventArgs e)
  {
    this.m_application.Clearance = this.m_clearance_numericUpDown.Value * TxApplication.Options.Units.LinearMultiplier;
    this.m_application.RefreshDisplay = this.m_displaySimulation_checkBox.Checked;
    this.m_application.CreateNotes = this.m_notes_checkBox.Checked;
    this.m_application.TCPTrack = this.m_tcpTrack_checkBox.Checked;
    ITxSweptVolumeHoldingObject simulatingObject = this.m_operation_txObjEditBoxCtrl.Object as ITxSweptVolumeHoldingObject;
    ITxLocatableObject checkWithObj = this.m_checkWith_txObjEditBoxCtrl.Object as ITxLocatableObject;
    this.m_report_button.Enabled = false;
    this.setUIElementsEnable(false);
    Cursor current = Cursor.Current;
    try
    {
      Cursor.Current = Cursors.WaitCursor;
      this.m_application.sampleInterferenceZone(simulatingObject, checkWithObj, this.m_includeCables_checkBox.Checked);
      EApInterferenceZoneErrorType error = this.m_application.Error;
      if (error == EApInterferenceZoneErrorType.NO_ERROR)
        this.m_report_button.Enabled = true;
      else
        this.reportError(error);
      TxApplication.RefreshDisplay();
    }
    catch (Exception ex)
    {
      this.reportError(EApInterferenceZoneErrorType.IZ_OPERATION_FAILED);
    }
    finally
    {
      Cursor.Current = current;
      new TxObjectTreeInternal().ListenToNewObjectCreation = true;
      this.setUIElementsEnable(true);
    }
  }

  private void m_report_button_Click(object sender, EventArgs e)
  {
    if (!TxAssemblyInfoEx.IsExcelInstalled(true, ""))
      return;
    this.generateReport();
  }

  private void CUiSVInterferenceZoneDlg_FormClosing(object sender, FormClosingEventArgs e)
  {
    if (!this.m_close_button.Enabled)
      e.Cancel = true;
    TxFormSettings.StoreFormValue((Form) this, "SWEPT_VOLUME_MULTIPLE_OPERATIONS_DLG_INCLUDE_CABLES", (object) this.m_includeCables_checkBox.Checked.ToString());
  }

  private void m_tcpTrack_checkBox_CheckedChanged(object sender, EventArgs e)
  {
    if (!this.m_tcpTrack_checkBox.Checked)
      return;
    if (this.isSelectedOperationMountedWorkpieceOperation())
    {
      this.m_tcpTrack_checkBox.Checked = false;
      ResourceManager resourceManager = new ResourceManager("DnProcessSimulateCommands.SweptVolume.StringTable", ((object) this).GetType().Assembly);
      string str1 = resourceManager.GetString("IZ_NAME");
      string str2 = resourceManager.GetString("IZ_CAN_NOT_GENERATE_TCP_TRACK_FOR_MOUNTED_WORKPIECE");
      MessageBoxIcon messageBoxIcon = MessageBoxIcon.Asterisk;
      int num = (int) TxMessageBox.Show(str2, str1, MessageBoxButtons.OK, messageBoxIcon);
    }
    else
    {
      if (!this.isSelectedOperationObjectFlowOperation())
        return;
      this.m_tcpTrack_checkBox.Checked = false;
      ResourceManager resourceManager = new ResourceManager("DnProcessSimulateCommands.SweptVolume.StringTable", ((object) this).GetType().Assembly);
      string str3 = resourceManager.GetString("IZ_NAME");
      string str4 = resourceManager.GetString("IZ_CAN_NOT_GENERATE_TCP_TRACK_FOR_OBJECT_FLOW");
      MessageBoxIcon messageBoxIcon = MessageBoxIcon.Asterisk;
      int num = (int) TxMessageBox.Show(str4, str3, MessageBoxButtons.OK, messageBoxIcon);
    }
  }
}
